import pysrv
class SessionKeyCmd:
	id = 0
	content=""
	def parse(self,content):
		msg = pysrv.Msg()
		msg.set(content)
		self.id = msg.popInt(2)
		self.content = msg.popStr(4)
	def stream(self):
		msg = pysrv.Msg()
		msg.pushInt(2,self.id)
		msg.pushStr(4,self.content)
		return msg.content()
class Tick(pysrv.PyTickDelegate):
	def update(self):
		pass

class Server(pysrv.PyServerDelegate):
	def goInit(self):
		self.init(6007)
	def msgParseContent(self,id,content):
		print("server::msgParse",content)
		keyCmd = SessionKeyCmd()
		keyCmd.parse(content)
		print("conent parse",keyCmd.id,keyCmd.content)
		self.sendString(id,"msgParseContent")
		self.closeTask(id)
	def newTCPTask(self,id):
		self.sendString(id,"newTCPTask")
	def taskDestroyed(self,id):
		print("Server::taskDestroyed",id)
class Client(pysrv.PyClientDelegate):
	def goInit(self):
		self.init("127.0.0.1",6008)
		self.sendString("goInit")
	def connectGet(self):
		print("Client::connectGet")
		keyCmd = SessionKeyCmd()
		keyCmd.id = 100
		keyCmd.content="hel"
		self.sendString(keyCmd.stream())
	def msgParseContent(self,content):
		print("ClientTask::msgParse",content)
	def connectLoss(self):
		print("Client::connectLoss")

server = Server("PyServer")
server.goInit()

client =  Client()
client.goInit()
tick = Tick(1)
server.addTick(tick)
server.addClient(client)

server.start()



